// ============================== 导入依赖 ============================== //

import * as echarts from 'echarts'

// 颜色名称, 渐变开始, 渐变结束, 面积透明, 曲线线条, 曲线阴影
const COLOR = [
  ['red', '#FFB497', '#FF6B56', 'rgba(233,77,77,.5)', '#FF6A55', '#E47667'], // 红
  ['blue', '#C0D9FF', '#409EFF', 'rgba(44,117,229,.5)', '#2D75E5', '#5D96EE'], // 蓝
  ['green', '#76E1AE', '#00B07E', 'rgba(0,176,126,.5)', '#00B07E', '#00B07E'], // 绿
  ['golden', '#FFDFA0', '#F3B844', 'rgba(243,184,68,.5)', '#FFBB36', '#FAD38A'], // 金
  ['cyan', '#57ECF8', '#49C1F5', 'rgba(243,184,68,.5)', '#FFBB36', '#FAD38A'], // 青
]

// ============================== 导出常量 ============================== //

export default {
  // —————————————————————————————— 颜色属性 (优先级递减) —————————————————————————————— //

  PROPS: {
    color: { default: undefined }, // 自定义颜色
    ...COLOR.reduce((obj, [name]) => {
      obj[name] = { type: Boolean, default: false } // 是否为某色
      return obj
    }, {}),
  },

  // —————————————————————————————— 条形图颜色 —————————————————————————————— //

  BAR_COLOR: COLOR.reduce((obj, [name, start, end]) => {
    obj[name] = new echarts.graphic.LinearGradient(1, 0, 0, 1, [
      { offset: 0, color: start },
      { offset: 1, color: end },
    ])
    return obj
  }, {}),

  // —————————————————————————————— 柱状图颜色 —————————————————————————————— //

  COLUMN_COLOR: COLOR.reduce((obj, [name, start, end]) => {
    obj[name] = new echarts.graphic.LinearGradient(0, 0, 0, 1, [
      { offset: 0, color: start },
      { offset: 1, color: end },
    ])
    return obj
  }, {}),

  // —————————————————————————————— 面积图颜色 —————————————————————————————— //

  AREA_COLOR: COLOR.reduce((obj, [name, , , rgba]) => {
    obj[name] = new echarts.graphic.LinearGradient(0, 0, 0, 1, [
      { offset: 0, color: rgba },
      { offset: 0.8, color: '#fff' },
    ])
    return obj
  }, {}),

  // —————————————————————————————— 曲线图系列 —————————————————————————————— //

  LINE_SERIE: COLOR.reduce((obj, [name, , , , color, shadowColor]) => {
    obj[name] = {
      type: 'line',
      smooth: 0.3,
      data: [],
      showSymbol: false,
      itemStyle: {
        color,
      },
      lineStyle: {
        width: 2,
        color,
        shadowColor,
        shadowBlur: 5,
        shadowOffsetY: 8,
      },
    }
    return obj
  }, {}),
}
